---
title: "IO Replication (Fig1)"
author: "Jason Lyall"
date: "4/28/2019"
output: html_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(tidyverse)
library(estimatr)
library(margins)
library(sandwich)
library(scales)
library(readxl)
library(ggplot2)

```

## Load data 
ACAPtimetrend <- read.csv("/Users/…/ACAPtimetrend.csv")

```

## Figure 1a (Density Plot by Incident Status) 
```{r}

ggplot(ACAPtimetrend, aes(x=acap, color=Status, shape=Status)) + geom_density() + xlab("ACAP Incidents") + ylab("Density") + theme_bw() +  theme(panel.background = element_blank(),legend.title = element_blank(), legend.justification = c(.01, .01), legend.position= c(.05, .05)) + scale_color_manual(values=c("red", "blue"))
ggplot(ACAPtimetrend, aes(x=acap, color=Status, shape=Status)) + geom_density() + xlab("ACAP Incidents") + ylab("Density") + theme_bw() +  theme(panel.background = element_blank(),legend.title = element_blank(), legend.justification = c(.01, .01), legend.position= c(.05, .05)) + scale_color_manual(values=c("black", "grey69"))


```

## Figure 1b (Stacked Area Plot of Approved, Abandoned, and Total Incidents) 
```{r}


ggplot(ACAPtimetrend, aes(x=time2, y=acap, fill=Status)) + geom_area(color="black", size=.2, alpha=.4) + theme_bw() + xlab("Months") + ylab("ACAP Incidents") +  theme(panel.background = element_blank(),legend.title = element_blank(), legend.justification = c(0,1), legend.position= c(.02,.99)) + scale_color_manual(values=c("red", "blue"))
ggplot(ACAPtimetrend, aes(x=time2, y=acap, fill=Status)) + geom_area(color="black", size=.2, alpha=.4) + theme_bw() + xlab("Months") + ylab("ACAP Incidents") +  theme(panel.background = element_blank(),legend.title = element_blank(), legend.justification = c(0,1), legend.position= c(.02,.99)) + scale_fill_grey()


``` 

## Figure 1c (Proportion of Incidents Approved) 
```{r}

ggplot(ACAPtimetrend, aes(x=time3, y=Ratio)) + geom_smooth() + theme_bw() + xlab("Months") + ylab("Proportion of Incidents Deemed Eligible")
ggplot(ACAPtimetrend, aes(x=time3, y=Ratio)) + geom_smooth(color="black") + theme_bw() + xlab("Months") + ylab("Proportion of Incidents Deemed Eligible") 
